/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package wicketsystem;

import java.util.Calendar;
import java.util.Date;
import java.util.TimeZone;

/**
 *
 * @author Daryna_Ragimova
 */
public class TypicalCard implements Card {

    protected int id;
    protected final Types type;
    private Date dateOfFinish;

    protected TypicalCard(int id, Types type) {
        this.id = id;
        this.type = type;
    }

    public TypicalCard(int id, Types type, int term, Date dateCreation) {
        this.id = id;
        this.type = type;
        dateOfFinish = calcutateDateOfFinish(dateCreation, term);
    }

    public Types getType() {
        return type;
    }

    @Override
    public boolean check() {
        Calendar localCalendar = Calendar.getInstance(TimeZone.getDefault());
        Date currentTime = localCalendar.getTime();
        if (currentTime.after(dateOfFinish)) {
            return false;
        }
        return true;
    }

    @Override
    public boolean getTrip() {
        return check();
    }

    private Date calcutateDateOfFinish(Date dateCreation, int term) {
        Calendar c = Calendar.getInstance();
        c.setTime(dateCreation);
        c.add(Calendar.DATE, term);
        return c.getTime();
    }
}
